//
//  SettingViewAdapter.m
//  Weibbo
//
//  Created by 李 林刚 on 13-8-11.
//  Copyright (c) 2013年 Omnivores. All rights reserved.
//

#import "SettingViewAdapter.h"
#import "SettingFirstCell.h"

@implementation SettingViewAdapter


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return [_list count];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [[_list objectAtIndex:section]count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section==0) {
        switch (indexPath.row) {
            case 0:
            case 1:
            {
                static NSString *defaultCellIdentifier = @"ShareBindCell";
                SettingFirstCell *cell = [tableView dequeueReusableCellWithIdentifier:defaultCellIdentifier];
                if (cell == nil)
                {
                    cell = [[[SettingFirstCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:defaultCellIdentifier]autorelease];
                    cell.selectionStyle = UITableViewCellSelectionStyleNone;
                }
                if (indexPath.row==0) cell.tag = ShareTypeSina;
                else cell.tag = ShareTypeTencentOAuth;
                [cell UpdateBindCell];
                return cell;
            }
                break;
            default:
            {
                static NSString *defaultCellIdentifier = @"Cell";
                UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:defaultCellIdentifier];
                if (cell == nil)
                {
                    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:defaultCellIdentifier]autorelease];
                    cell.selectionStyle = UITableViewCellSelectionStyleNone;
                }
                 cell.textLabel.textAlignment = NSTextAlignmentLeft;
                [cell.textLabel setTextColor:UIBlackColor];
                [cell.textLabel setText:[[_list objectAtIndex:indexPath.section] objectAtIndex:indexPath.row]];
                UILabel  *qqLab = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetWidth(cell.frame)-130, 0, 100, 44)];
                [qqLab setTextAlignment:NSTextAlignmentRight];
                 qqLab.backgroundColor = UIClearColor;
                [qqLab setText:@"177787979"];
                [qqLab setTextColor:UIBlackColor];
                [cell.contentView addSubview:qqLab];
                [qqLab release];
                return cell;
            }
                break;
        }
    }
    else
    {
        static NSString *defualtSection2CellIdentifier = @"defualtSection2CellIdentifier";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:defualtSection2CellIdentifier];
        if (cell == nil)
        {
            cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:defualtSection2CellIdentifier]autorelease];
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        }
        cell.textLabel.textAlignment = NSTextAlignmentLeft;
        [cell.textLabel setTextColor:UIBlackColor];
        [cell.textLabel setText:[[_list objectAtIndex:indexPath.section] objectAtIndex:indexPath.row]];
        
        if (indexPath.row == [[_list objectAtIndex:indexPath.section]count] - 1) {
            cell.accessoryType = UITableViewCellAccessoryNone;
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            UILabel *versionLbl = (UILabel*)[cell.contentView viewWithTag:10000];
            if (!versionLbl) {
                versionLbl = [[UILabel alloc]initWithFrame:CGRectMake(190, 0, 100, 44)];
                versionLbl.textColor = [UIColor blackColor];
                versionLbl.tag=10000;
                versionLbl.font = [UIFont systemFontOfSize:15];
                versionLbl.textAlignment = UITextAlignmentRight;
                versionLbl.backgroundColor = [UIColor clearColor];
                [cell.contentView addSubview:versionLbl];
                [versionLbl release];
            }
            versionLbl.text = [[NSBundle mainBundle]objectForInfoDictionaryKey:@"CFBundleVersion"];
        }
        else{
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
            cell.selectionStyle = UITableViewCellSelectionStyleBlue;
            UILabel *versionLbl = (UILabel*)[cell.contentView viewWithTag:10000];
            if (versionLbl) {
                versionLbl.text =@"";
            }
        }
        return cell;
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 44.0f;
}

@end
